home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / rjs.lha / RJS / String / src / trim.C < prev    next >
C/C++ Source or Header  |  1991-06-14  |  639b  |  42 lines

  1. #include "String.h"
  2. #include "ctype.h"
  3.  
  4. RJS_String &RJS_String::trim(Side t)
  5. {
  6. char *p,*q;
  7. int len,i;
  8.  
  9.   q=p=sd.data;
  10.  
  11.   if (isspace(*q) && (t & Left)) {
  12.       len=0; i=0;
  13.       while (i<length() && isspace(*q)) q++,i++;    // skip white space
  14.       while (i<length()) {    // copy non-white space
  15.         *p++ = *q++;
  16.         i++;
  17.         len++;
  18.       }
  19.   } else len=length();
  20.  
  21.   if (t & Right) while(len && isspace(sd.data[len-1])) len--;
  22.  
  23.   if (len!=length()) trunc(len);
  24.  
  25.   return *this;
  26. }
  27.  
  28. RJS_String trim(const char *s,Side t)
  29. {
  30. RJS_String temp(s);
  31.  
  32.   return temp.trim(t);
  33. }
  34.  
  35. RJS_String trim(const RJS_String &s,Side t)
  36. {
  37. RJS_String temp(s);
  38.  
  39.   return temp.trim(t);
  40. }
  41.  
  42.